package rule

// deprecated placeholder
import (
	"encoding/binary"
	"net"
	"strings"
)

// SplitAndTrim 按分隔符拆分并 Trim 去除空白, 过滤空串
func SplitAndTrim(s, sep string) []string {
	if s == "" {
		return nil
	}
	parts := strings.Split(s, sep)
	res := make([]string, 0, len(parts))
	for _, p := range parts {
		p = strings.TrimSpace(p)
		if p != "" {
			res = append(res, p)
		}
	}
	return res
}

// IPv4ToUint32 将 IPv4 转为 uint32 (大端)；非法返回 0
func IPv4ToUint32(ip net.IP) uint32 {
	v4 := ip.To4()
	if v4 == nil {
		return 0
	}
	return binary.BigEndian.Uint32(v4)
}
